﻿using LdtJudge.DataEngine.Model.DataModel.SysCommon;
using LdtJudge.DataEngine.Model.XMLConfigModel.OptimzeMode;
using LdtJudge.DataEngine.Model.XMLConfigModel.SameNodeConfigModel;
using System;
using System.Collections.Generic;
using System.Xml;

namespace LdtDataEngin.ModuleDetail.BaseModule.MultiFack
{
    /// <summary>
    /// 要素最终待认定数据
    /// </summary>
    public class MultiFactUnConfirm : MultiFactBase
    {
        /// <summary>
        /// 分人员有异议要素
        /// </summary>
        public Dictionary<Tuple<string, string>, XmlNode> Personxml { get; set; } = new Dictionary<Tuple<string, string>, XmlNode>();
        /// <summary>
        /// 确认要素
        /// </summary>
        public XmlDocument ConfirmNode = new XmlDocument();

        public CaseCauseModel caseCauseModel;
        /// <summary>
        /// 形成最终待认定要素
        /// </summary>
        public Dictionary<Tuple<string, string>, XmlNode> Unpersonxml = new Dictionary<Tuple<string, string>, XmlNode>();

        /// <summary>
        /// 最终待认定数据处理;
        /// </summary>
        /// <param name="template">模板节点</param>
        /// <param name="personxml">人员数据</param>
        /// <param name="xmlConfigModels">配置数据</param>
        /// <param name="nodeHandleType">同节点判定类型</param>
        /// <returns></returns>
        public override string MultiFactHandleCommon(XmlNode template, Dictionary<Tuple<string, string>, XmlNode> personxml, List<SameNodeXml> xmlConfigModels, SameNodeHandleType nodeHandleType)
        {
            MultiFactExcept multiFact = new MultiFactExcept() ;

            string nodename = template.Name; // "事实要素";
            string templatexml = string.Format("<{0}></{0}>", template.ParentNode.Name);
            if (caseCauseModel != null)
            {
                templatexml = string.Format("<{0} 案由名称='{1}' 案由ID='{2}'></{0}>", template.ParentNode.Name, caseCauseModel.CC_Name, caseCauseModel.CC_ID);
            }
            //进行遍历分人员数据
            foreach (var person in personxml)
            {
                //新建一个此案由的根节点xml
                XmlDocument result = new XmlDocument();
                result.LoadXml(templatexml);
                XmlNode xmlNodeFact = result.CreateElement("事实要素");
                result.DocumentElement.AppendChild(xmlNodeFact);
                //排除
                multiFact.ExceptNode(template, person.Value, ConfirmNode, xmlConfigModels, xmlNodeFact, nodeHandleType);
                XmlNode xmlnodeTemp = result.Clone();
                if (Personxml.ContainsKey(person.Key))
                {
                    xmlNodeFact.RemoveAll();
                    multiFact.ExceptNode(template, xmlnodeTemp, Personxml[person.Key], xmlConfigModels, xmlNodeFact, nodeHandleType);
                }
                //去除空节点
                result = base.EscapeNodeIndexAndBlank(result);
                Unpersonxml.Add(person.Key, result);

                dataContext.InteractiveShow.LogShow("\r\n----------★" + person.Key.Item1 + "-" + person.Key.Item2 + "最终待认定的的要素为：★----------\r\n" + result.OuterXml);
            }
            return "";
        }

    }
}
